from openai import OpenAI

client = OpenAI(
    api_key="sk-on1j51cvbafu31osq7ukpslf3ace04fea1bk7ld3e4g26fjc",
    base_url="https://api.aihao123.cn/luomacode-api/open-api/v1/"
)

response = client.chat.completions.create(
    messages=[
        {'role': 'user', 'content': "鲁迅为什么打周树人？"},
    ],
    model='gpt-4',
    stream=True
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="", flush=True)
